﻿using DFGK_WMS.IRepository;
using DFGK_WMS.Model.Models;
using DFGK_WMS.WebAPI.Controllers.Result;
using Microsoft.AspNetCore.Mvc;

namespace DFGJ.WMS_PDA.WebAPI.Controllers.PDA
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PickingPositionController : Controller
    {
        private IPickingPositionRepository pickingPositionRepository { get; set; }
        public PickingPositionController(IPickingPositionRepository PickingPositionRepository)
        {
            pickingPositionRepository = PickingPositionRepository;
        }

        /// <summary>
        /// 添加拣选位
        /// </summary>
        /// <param name="pickingPosition"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddPickingPositon(PickingPositionModel pickingPosition)
        {
            string msg = "";
            if (pickingPosition == null)
            {
                return Ok(BaseResult.Result(false, "请求参数为空", "500"));
            }
            var IsOk = pickingPositionRepository.AddPickingPositon(pickingPosition, out msg);
            if (IsOk)
            {
                return Ok(BaseResult.Result(true, "添加成功", "200"));
            }
            return Ok(BaseResult.Result(false, msg, "500"));
        }

        /// <summary>
        /// 更新拣选位
        /// </summary>
        /// <param name="pickingPosition"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult UpdPickingPosition(PickingPositionModel PickingPositionCode)
        {
            string msg = "";
            if (PickingPositionCode == null)
            {
                return Ok(BaseResult.Result(false, "请求参数为空", "500"));
            }
            var IsOk = pickingPositionRepository.UpdPickingPosition(PickingPositionCode, out msg);
            if (IsOk)
            {
                return Ok(BaseResult.Result(true, "修改成功", "200"));
            }
            return Ok(BaseResult.Result(false, msg, "500"));
        }

        /// <summary>
        /// 删除拣选位
        /// </summary>
        /// <param name="pickingPositionId"></param>
        /// <returns></returns>
        [HttpDelete]
        public IActionResult DelPickingPosition(string PickingPositionCode)
        {
            string msg = "";
            if (PickingPositionCode == null)
            {
                return Ok(BaseResult.Result(false, "请求参数为空", "500"));
            }
            var IsOk = pickingPositionRepository.DelPickingPosition(PickingPositionCode, out msg);
            if (IsOk)
            {
                return Ok(BaseResult.Result(true, "删除成功", "200"));
            }
            return Ok(BaseResult.Result(false, msg, "500"));
        }

        /// <summary>
        /// 根据ID获取指定拣选位
        /// </summary>
        /// <param name="pickingPositionId"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetPickingPositionById(string PickingPositionCode)
        {
            if (PickingPositionCode == null)
            {
                return Ok(BaseResult.Result(false, "请求参数为空", "500"));
            }
            var list = pickingPositionRepository.GetPickingPositionById(PickingPositionCode);
            if (list != null)
            {
                return Ok(BaseResult.Result(list, "查询成功", "200"));
            }
            return Ok(BaseResult.Result(false, "查询失败", "500"));
        }

        /// <summary>
        /// 获取所有拣选位
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetAllPickingPositions()
        {
            var list = pickingPositionRepository.GetAllPickingPositions();
            if (list != null)
            {
                return Ok(BaseResult.Result(list, "查询成功", "200"));
            }
            return Ok(BaseResult.Result(false, "查询失败", "500"));
        }
    }
}
